import com.github.javafaker.Faker;
import com.opencsv.CSVWriter;
import lombok.Data;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

public class AccountGeneratorCSV {
    @Data
    public static class Account {
        private String username;
        private String nickname;
        private String password;
        private String passwordRepeat;
    }

    public static void main(String[] args) throws IOException {
        Faker faker = new Faker(Locale.SIMPLIFIED_CHINESE);
        List<Account> list = new ArrayList<>(800);

        for (int i = 0; i < 20000; i++) {
            Account acc = new Account();
            acc.setUsername(faker.letterify("user???????????"));
            acc.setNickname(faker.name().lastName() + faker.name().lastName() + UUID.randomUUID().toString().substring(0, 18));
            acc.setPassword(UUID.randomUUID().toString().substring(0, 18));
            acc.setPasswordRepeat(acc.getPassword());
            list.add(acc);
        }

        String fileName = "accounts.csv";
        try (CSVWriter writer = new CSVWriter(new FileWriter(fileName))) {
            // 写入表头
            String[] header = { "username", "nickname", "password", "passwordRepeat" };
            writer.writeNext(header);

            // 写入数据
            for (Account acc : list) {
                String[] data = {
                        acc.getUsername(),
                        acc.getNickname(),
                        acc.getPassword(),
                        acc.getPasswordRepeat()
                };
                writer.writeNext(data);
            }
        }

        System.out.println("生成完成：" + fileName);
    }
}
